package template

import (
	"go-quick/interface/itemplate"
	"strings"
)

type NodeDocument struct {
	Nodes []INode
}

type NodeWrapper struct {
	EndTag string
	nodes  []TNode
}

func (doc *NodeDocument) Execute(ctx *ExecutionContext, writer itemplate.IWriter) *Error {

	for _, node := range doc.Nodes {
		if err := node.Execute(ctx, writer); err != nil {
			return err
		}
	}
	return nil

}

type NodeHtml struct {
	token     *Token
	trimLeft  bool
	trimRight bool
}

func (n *NodeHtml) Execute(ctx *ExecutionContext, writer itemplate.IWriter) *Error {

	res := n.token.Val
	if n.trimLeft {
		res = strings.TrimLeft(res, tokenSpaceChars)
	}
	if n.trimRight {
		res = strings.TrimRight(res, tokenSpaceChars)
	}
	_, _ = writer.WriteString(res)
	return nil
}
